package com.xiaoli.userserver.api;

import com.xiaoli.user.api.IUserClient;
import com.xiaoli.user.dto.UserDTO;
import com.xiaoli.userserver.service.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserAPI implements IUserClient {

    @Autowired
    private IUserService userService;

    @Override
    public UserDTO getUserById(Long id) {
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(userService.getById(id), userDTO);
        return userDTO;
    }

    @Override
    public void updatePoint(Long id, Integer changePoint) {
        userService.updatePoint(id, changePoint);
        try {
            Thread.sleep(15 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
